package com.goods.webservice.service;

import com.goods.povos.Weather;
import com.goods.povos.WeatherPovo;
import com.goods.webservice.wsdl.EnglishChinese.ArrayOfString;
import com.goods.webservice.wsdl.EnglishChinese.EnglishChinese;
import com.goods.webservice.wsdl.EnglishChinese.EnglishChineseSoap;
import com.goods.webservice.wsdl.mobile.MobileCodeWS;
import com.goods.webservice.wsdl.mobile.MobileCodeWSSoap;
import com.goods.webservice.wsdl.weatherWS.WeatherWS;
import com.goods.webservice.wsdl.weatherWS.WeatherWSSoap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WebServiceService {
    //    翻译
    @Autowired
    private EnglishChinese englishChinese;
    //    手机号归属地查询
    @Autowired
    private MobileCodeWS mobileCodeWS;
    //    天气查询
    @Autowired
    private WeatherWS weatherWS;


    public String selectMobile(String mobile) {
        MobileCodeWSSoap proxy = mobileCodeWS.getMobileCodeWSSoap();
        return proxy.getMobileCodeInfo(mobile, null);
    }

    public List<String> english(String wordKey) {
        EnglishChineseSoap proxy = englishChinese.getEnglishChineseSoap();
        ArrayOfString array = proxy.translatorString(wordKey);
        return array.getString();
    }

    public byte[] englishChineseMP3(String mp3) {
        EnglishChineseSoap proxy = englishChinese.getEnglishChineseSoap();
        return proxy.getMp3(mp3);
    }

    public List<String> weater(String address) {
        WeatherWSSoap proxy = weatherWS.getWeatherWSSoap();
        com.goods.webservice.wsdl.weatherWS.ArrayOfString array = proxy.getWeather(address, null);

        List<String> list = array.getString();
        List<String> weather = new ArrayList<String>();
        weather.add(list.get(1));//城市
        weather.add(list.get(7));//天气
        weather.add(list.get(8));//温度
        weather.add(list.get(10));//天气图片1
        weather.add(list.get(11));//天气图片2

        return weather;
    }

    //    返回两天的天气
    public WeatherPovo getWeater(String city) {
        WeatherWSSoap proxy = weatherWS.getWeatherWSSoap();
        List<String> res = proxy.getWeather(city, null).getString();
        String today_image_path = "/goods/weather_img/" + res.get(10);
        String today_desc = res.get(7).substring(res.get(7).indexOf(" "));
        String today_temperature_value = res.get(8).replace("/", "~");
        String today_temperature = "今 " + today_desc + " " + today_temperature_value;
        String tomorrow_image_path = "/goods/weather_img/" + res.get(15);
        String tomorrow_desc = res.get(12).substring(res.get(12).indexOf(" "));
        String tomorrow_temperature_value = res.get(13).replace("/", "~");
        String tomorrow_temperature = "明 " + tomorrow_desc + " " + tomorrow_temperature_value;
        Weather today = new Weather(today_image_path, today_temperature);
        Weather tomorrow = new Weather(tomorrow_image_path, tomorrow_temperature);
        WeatherPovo povo = new WeatherPovo();
        povo.setToday(today);
        povo.setTomorrow(tomorrow);
        return povo;
    }
}
